﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;

namespace ERPStore.Cart.Repositories
{
    public class CartDbContext : DbContext
    {
		public CartDbContext()
		{

		}

		public CartDbContext(string connectionString)
			: base(connectionString)
		{
			var csBuilder = new SqlConnectionStringBuilder(this.Database.Connection.ConnectionString);
			csBuilder.ApplicationName = this.GetType().Assembly.FullName + "," + System.Environment.MachineName;
			this.Database.Connection.ConnectionString = csBuilder.ConnectionString;

			Configuration.ProxyCreationEnabled = false;
			Configuration.AutoDetectChangesEnabled = true;
			Configuration.LazyLoadingEnabled = false;
		}

        public DbSet<Datas.Cart> Carts { get; set; }
        public DbSet<Datas.CartItem> CartItems { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new Mapping.CartMap());
            modelBuilder.Configurations.Add(new Mapping.CartItemMap());
        }
    }
}
